package br.com.gbvbahia.mybooks;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Login  extends ActivityMae {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		final SharedPreferences preferencia = getSharedPreferences("config",
				Context.MODE_PRIVATE);
		boolean loginAtivo = preferencia.getBoolean(Config.LOGIN_ATIVO, false);
		if(loginAtivo){
			final EditText textLogin = (EditText) findViewById(R.id.editLoginLogin);
			final EditText textSenha = (EditText) findViewById(R.id.editLoginSenha);
			final Button btnLogar = (Button) findViewById(R.id.btnLoginLogar);
			final String login = preferencia.getString(Config.LOGIN, getString(R.string.informarLogin));
			final String senha = preferencia.getString(Config.SENHA, "");
			
			btnLogar.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					if(login.equals(textLogin.getText().toString())
							&& senha.equals(textSenha.getText().toString())){
						startActivity(new Intent(getBaseContext(), Principal.class));
					}else {
						Toast.makeText(getBaseContext(),
								getString(R.string.aviso_12),
								Toast.LENGTH_SHORT).show();
						return;
					}
				}
			});
		} else {
			startActivity(new Intent(getBaseContext(), Principal.class));
		}
	}

	
}
